package cn.zebra.dev.product.module.question.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.product.module.question.dao.ProductQuestionDao;
import cn.zebra.dev.product.module.question.entity.ProductQuestionEntity;
import cn.zebra.dev.product.module.question.service.ProductQuestionService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author HH
 */
@Service
public class ProductQuestionServiceImpl extends ServiceImpl<ProductQuestionDao, ProductQuestionEntity> implements ProductQuestionService {
    @Override
    public PageUtils<ProductQuestionEntity> findPage(Map<String, Object> map) {
        QueryWrapper<ProductQuestionEntity> wrapper = new QueryWrapper<>();
        wrapper.select("id, product_id, product_name, member_id, member_name, question_content");
        wrapper.apply(map.containsKey("memberId"), "member_id = {0}", map.get("memberId"));
        wrapper.apply(map.containsKey("productId"), "product_id = {0}", map.get("productId"));
        wrapper.apply(map.containsKey("deleteFlag"), "delete_flag = {0}", map.get("deleteFlag"));
        wrapper.orderByDesc("id");
        IPage<ProductQuestionEntity> iPage = this.page(
                new Query<ProductQuestionEntity>(map).getPage(),
                wrapper
        );
        return new PageUtils<>(iPage);
    }
}
